package com.nchuAo.util;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;

@Data
public class Response {
	private Integer code;
	private String message;
	private Map<String,Object> data = new HashMap<>();

	//1. 成功时的方法
	public static Response ok(){
		Response response = new Response();
		response.setCode(200);
		response.setMessage("操作成功！");
		return response;
	}
	//2. 失败时的调用方法
	public static Response error(){
		Response response = new Response();
		response.setCode(500);
		response.setMessage("操作失败！");
		return response;
	}

	// 4. 修改出错信息
	public Response message(String message){
		this.setMessage(message);
		return this;
	}
	// 5. 修改错误码
	public Response code(Integer code){
		this.setCode(code);
		return this;
	}
	//4. 设置添加数据
	public Response data(String key, Object value){
		this.data.put(key,value);
		return this;
	}
	public Response data(Map<String,Object> map){
		this.setData(map);
		return this;
	}

}
